package com.yb.producer.service.hanlder;

import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.HashMap;
import java.util.Map;

/**
 * @author biaoyang
 * @Date
 */
@Slf4j
@RestControllerAdvice
public class MyGlobalExceptionHandler {

    @ApiOperation("这个是用于拦截处理接口层异常的统一异常处理(测试网关异常捕获)")
    @ResponseStatus(HttpStatus.BAD_REQUEST)
    @ExceptionHandler(Exception.class)
    public Map<String,Object> exception(Exception e){
        Map<String,Object> map = new HashMap<>(2);
        map.put("status", HttpStatus.BAD_REQUEST.value());
        map.put("message","网络异常");
        log.info("统一处理异常:{}",e.getMessage());
        return map;
    }

}
